const Router = require('koa-router')
const fs = require('fs')
const router = new Router()

// 用户登录接口
router.post('/login', async ctx => {
  const password = ctx.request.body.password
  if (password == '123456') {
    let result = { token: 'Admin Token' }
    ctx.body = { code: 200, data: result, messge: '请求成功！', ok: 'yes' }
  } else {
    ctx.body = { code: 500, message: 'password is error!' }
  }
})

// 获取商品分类列表
router.get('/getList', async ctx => {
  try {
    let result = [{ id: 0, name: '商品1' }]
    ctx.body = { code: 200, data: result }
  } catch (error) {
    ctx.body = { code: 500, message: error }
  }
})

// 根据商品ID获取商品详情
router.post('/postMsg', async ctx => {
  try {
    let goodsId = ctx.request.body.goodsId
    const data = [{ id: 100, goodsId: goodsId, name: '西瓜' }]
    ctx.response.body = { code: 200, data }
  } catch (error) {
    console.log('error', error)
    ctx.response.body = { code: 500, data: error }
  }
})

module.exports = router
